{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import QUANTAXIS as QA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "user = QA.QA_User(username='test', password= 'test')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " prortfolio with user_cookie  USER_83ImTVUM  already exist!!\n"
     ]
    }
   ],
   "source": [
    "port = user.new_portfolio('test')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "acc = port.new_account(account_cookie='test_frozen', market_type=QA.MARKET_TYPE.FUTURE_CN)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'cash': 1000000, 'hold': {}}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "acc.init_assets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "< QA_Account test_frozen market: future_cn>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "acc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!receive deal\n"
     ]
    }
   ],
   "source": [
    "acc.receive_deal(code='RB1905',trade_amount=10, trade_time='2019-02-28 15:00:00',trade_price=3605,trade_towards=QA.ORDER_DIRECTION.BUY_OPEN, trade_id='t',order_id='t',realorder_id='t')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'RB1905': {'2': {'money': 3605.0, 'amount': 10, 'avg_price': 3605.0},\n",
       "  '-2': {'money': 0, 'amount': 0, 'avg_price': 0}}}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "acc.frozen"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "account test_frozen save\n"
     ]
    }
   ],
   "source": [
    "user.save()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "b= user['test']['test_frozen']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>datetime</th>\n",
       "      <th>code</th>\n",
       "      <th>price</th>\n",
       "      <th>amount</th>\n",
       "      <th>cash</th>\n",
       "      <th>order_id</th>\n",
       "      <th>realorder_id</th>\n",
       "      <th>trade_id</th>\n",
       "      <th>account_cookie</th>\n",
       "      <th>commission</th>\n",
       "      <th>tax</th>\n",
       "      <th>message</th>\n",
       "      <th>frozen</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-02-28 15:00:00</td>\n",
       "      <td>RB1905</td>\n",
       "      <td>3605.0</td>\n",
       "      <td>10</td>\n",
       "      <td>963946.395</td>\n",
       "      <td>t</td>\n",
       "      <td>t</td>\n",
       "      <td>t</td>\n",
       "      <td>test_frozen</td>\n",
       "      <td>3.605</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>36050.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              datetime    code   price  amount        cash order_id  \\\n",
       "0  2019-02-28 15:00:00  RB1905  3605.0      10  963946.395        t   \n",
       "\n",
       "  realorder_id trade_id account_cookie  commission  tax message   frozen  \n",
       "0            t        t    test_frozen       3.605    0    None  36050.0  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b.history_table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'RB1905': {'2': {'money': 3605.0, 'amount': 10, 'avg_price': 3605.0},\n",
       "  '-2': {'money': 0, 'amount': 0, 'avg_price': 0}}}"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b.frozen"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!receive deal\n"
     ]
    }
   ],
   "source": [
    "b.receive_deal(code='RB1905',trade_amount=10, trade_time='2019-02-28 21:00:00',trade_price=3605,trade_towards=QA.ORDER_DIRECTION.SELL_CLOSE, trade_id='t',order_id='t',realorder_id='t')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>datetime</th>\n",
       "      <th>code</th>\n",
       "      <th>price</th>\n",
       "      <th>amount</th>\n",
       "      <th>cash</th>\n",
       "      <th>order_id</th>\n",
       "      <th>realorder_id</th>\n",
       "      <th>trade_id</th>\n",
       "      <th>account_cookie</th>\n",
       "      <th>commission</th>\n",
       "      <th>tax</th>\n",
       "      <th>message</th>\n",
       "      <th>frozen</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-02-28 15:00:00</td>\n",
       "      <td>RB1905</td>\n",
       "      <td>3605.0</td>\n",
       "      <td>10</td>\n",
       "      <td>963946.395</td>\n",
       "      <td>t</td>\n",
       "      <td>t</td>\n",
       "      <td>t</td>\n",
       "      <td>test_frozen</td>\n",
       "      <td>3.605</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>36050.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-02-28 21:00:00</td>\n",
       "      <td>RB1905</td>\n",
       "      <td>3605.0</td>\n",
       "      <td>-10</td>\n",
       "      <td>999992.790</td>\n",
       "      <td>t</td>\n",
       "      <td>t</td>\n",
       "      <td>t</td>\n",
       "      <td>test_frozen</td>\n",
       "      <td>3.605</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              datetime    code   price  amount        cash order_id  \\\n",
       "0  2019-02-28 15:00:00  RB1905  3605.0      10  963946.395        t   \n",
       "1  2019-02-28 21:00:00  RB1905  3605.0     -10  999992.790        t   \n",
       "\n",
       "  realorder_id trade_id account_cookie  commission  tax message   frozen  \n",
       "0            t        t    test_frozen       3.605    0    None  36050.0  \n",
       "1            t        t    test_frozen       3.605    0    None      0.0  "
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b.history_table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'RB1905': {'2': {'money': 0, 'amount': 0, 'avg_price': 0},\n",
       "  '-2': {'money': 0, 'amount': 0, 'avg_price': 0}}}"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b.frozen"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!receive deal\n"
     ]
    }
   ],
   "source": [
    "b.receive_deal(code='RB1905',trade_amount=10, trade_time='2019-02-28 21:00:00',trade_price=3605,trade_towards=QA.ORDER_DIRECTION.SELL_OPEN, trade_id='t',order_id='t',realorder_id='t')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'RB1905': {'2': {'money': 0, 'amount': 0, 'avg_price': 0},\n",
       "  '-2': {'money': 3605.0, 'amount': 10, 'avg_price': 3605.0}}}"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b.frozen"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1000000, 963946.395, 999992.79, 963939.185]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b.cash"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!receive deal\n"
     ]
    }
   ],
   "source": [
    "b.receive_deal(code='RB1905',trade_amount=10, trade_time='2019-02-28 21:00:00',trade_price=3615,trade_towards=QA.ORDER_DIRECTION.BUY_CLOSETODAY, trade_id='t',order_id='t',realorder_id='t')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>datetime</th>\n",
       "      <th>code</th>\n",
       "      <th>price</th>\n",
       "      <th>amount</th>\n",
       "      <th>cash</th>\n",
       "      <th>order_id</th>\n",
       "      <th>realorder_id</th>\n",
       "      <th>trade_id</th>\n",
       "      <th>account_cookie</th>\n",
       "      <th>commission</th>\n",
       "      <th>tax</th>\n",
       "      <th>message</th>\n",
       "      <th>frozen</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-02-28 15:00:00</td>\n",
       "      <td>RB1905</td>\n",
       "      <td>3605.0</td>\n",
       "      <td>10</td>\n",
       "      <td>963946.395</td>\n",
       "      <td>t</td>\n",
       "      <td>t</td>\n",
       "      <td>t</td>\n",
       "      <td>test_frozen</td>\n",
       "      <td>3.605</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>36050.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-02-28 21:00:00</td>\n",
       "      <td>RB1905</td>\n",
       "      <td>3605.0</td>\n",
       "      <td>-10</td>\n",
       "      <td>999992.790</td>\n",
       "      <td>t</td>\n",
       "      <td>t</td>\n",
       "      <td>t</td>\n",
       "      <td>test_frozen</td>\n",
       "      <td>3.605</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2019-02-28 21:00:00</td>\n",
       "      <td>RB1905</td>\n",
       "      <td>3605.0</td>\n",
       "      <td>-10</td>\n",
       "      <td>963939.185</td>\n",
       "      <td>t</td>\n",
       "      <td>t</td>\n",
       "      <td>t</td>\n",
       "      <td>test_frozen</td>\n",
       "      <td>3.605</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>36050.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2019-02-28 21:00:00</td>\n",
       "      <td>RB1905</td>\n",
       "      <td>3615.0</td>\n",
       "      <td>10</td>\n",
       "      <td>999885.570</td>\n",
       "      <td>t</td>\n",
       "      <td>t</td>\n",
       "      <td>t</td>\n",
       "      <td>test_frozen</td>\n",
       "      <td>3.615</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              datetime    code   price  amount        cash order_id  \\\n",
       "0  2019-02-28 15:00:00  RB1905  3605.0      10  963946.395        t   \n",
       "1  2019-02-28 21:00:00  RB1905  3605.0     -10  999992.790        t   \n",
       "2  2019-02-28 21:00:00  RB1905  3605.0     -10  963939.185        t   \n",
       "3  2019-02-28 21:00:00  RB1905  3615.0      10  999885.570        t   \n",
       "\n",
       "  realorder_id trade_id account_cookie  commission  tax message   frozen  \n",
       "0            t        t    test_frozen       3.605    0    None  36050.0  \n",
       "1            t        t    test_frozen       3.605    0    None      0.0  \n",
       "2            t        t    test_frozen       3.605    0    None  36050.0  \n",
       "3            t        t    test_frozen       3.615    0    None      0.0  "
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b.history_table"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  },
  "latex_envs": {
   "LaTeX_envs_menu_present": true,
   "autoclose": false,
   "autocomplete": true,
   "bibliofile": "biblio.bib",
   "cite_by": "apalike",
   "current_citInitial": 1,
   "eqLabelWithNumbers": true,
   "eqNumInitial": 1,
   "hotkeys": {
    "equation": "Ctrl-E",
    "itemize": "Ctrl-I"
   },
   "labels_anchors": false,
   "latex_user_defs": false,
   "report_style_numbering": false,
   "user_envs_cfg": false
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
